<?php
//include './common/home.php';

$title   = '丁江的论坛';
$web_site = WEB_SITE;

$table   = DB_TABLE_CG;
$fields  = 'classname,orderby,compere,cid';
/*
//获取大板块
$where     = 'where parentid=0 order by orderby';	
$data_one1 = select($link,$table,$fields,$where);
$count     = count($data_one1);
//var_dump($data_one1);
//获取小版块
$where     = 'where parentid=1 order by orderby desc';
$data_one2 = select($link,$table,$fields,$where);

//var_dump($data_one2);	
*/			
$data_big = select($link,DB_TABLE_CG,'*', "order by orderby");
var_dump($data_big)
/********************************************************/
/******获取板块的具体信息************************************/
$table  = DB_TABLE_CG;
$fields = 'cid';
$where  = "where lastpost=1";
$res = select($link,$table,$fields,$where);
//var_dump($res);
$num = count($res);
//var_dump($num);

for ($i=0;$i<$num;$i++) {
	$cid[] = $res[$i]['cid'];
	//var_dump($res[$i]['cid']);
}

foreach ($cid as $k => $v) {
	
	$cid 	 = $v; 
	//var_dump($cid);
	//用 classid=cid 取值
	$table   = DB_TABLE_DETAIL;
	$fields  = 'authorid , first, title, addtime,id,classid';
	$where   = "where first=1 and classid=$cid order by addtime desc limit 0,1";
	$data_one3 = select($link,$table,$fields,$where);
	//var_dump($data_one3);
	$authorid  = $data_one3[0][authorid];
	//var_dump($authorid);
	//var_dump($data_one3[0]['id']);

	//用uid在bbs_user表中取username
	$table  = DB_TABLE_USER;
	$fields = 'username';
	$where  = "where uid=$authorid";
	$data_user = select($link,$table,$fields,$where);
	//var_dump($data_user);

}




/********************************************************/
/*
$table   = DB_TABLE_CG.' where parentid>0';
$fields = 'cid';
$where  = "order by cid";
$num    = idCount($link,$table,$fields);
//var_dump($num);
$res    = select($link,$table,$fields,$where);
//var_dump($res);
//通过authorid==id 跨表查 username
	//先将所有id放入数组中
for ($i=0;$i<$num;$i++) {
	$cid[] = $res[$i]['cid'];
	//var_dump($res[$i]['cid']);
}
//var_dump($cid);

	//拿出数组中的cid
foreach ($cid as $k => $v) {
	
	$cid 	 = $v; 
	//var_dump($cid);
	//用 classid=cid 取值
	$table   = DB_TABLE_DETAIL;
	$fields  = 'authorid , first, title, addtime,id,classid';
	$where   = "where first=1 and classid=$cid order by addtime desc limit 0,1";
	$data_one3 = select($link,$table,$fields,$where);
	//var_dump($data_one3);
	$authorid  = $data_one3[0][authorid];
	//var_dump($authorid);
	//var_dump($data_one3[0]['id']);

	//用uid在bbs_user表中取username
	$table  = DB_TABLE_USER;
	$fields = 'username';
	$where  = "where uid=$authorid";
	$data_user = select($link,$table,$fields,$where);
	//var_dump($data_user);

}
*/

//var_dump($data_one3);
//查询板块获取总条数(由classid值决定)
$table  = DB_TABLE_DETAIL." where first=1 and classid=$cid";
$fields = id;
$total  = idCount($link,$table,$fields);  

/***********今日发帖数********************************/
//var_dump($res[0]['addtime']);

for ($i=0;$i<count($data_one3);$i++){

	if ($data_one3[$i]['addtime'] > strtotime('00:00:00')) {

		$rows[] = $data_one3[$i]['addtime'];
		//var_dump($rows);
		$today_count = count($rows);

		//var_dump($today_count);
	}

}


/********************************************************/

$vars = compact('title','web_site','data_one1','data_one2','res','data_one3','data_user','cid','today_count','total','count','data_big');
display('num_one.html',$vars);




